<div th:fragment="control_table_base">
<script type="text/javascript">
	function metadata_table(params)
	{
		this.metadata = $.extend({}, {
			TITLE : {
				TEXT : "表格标题",
				HIDE : false
			},
			SIZE : {
				HEIGHT : 300,
				WIDTH : 90
			}
		}, params);
		this.getMetadata = function(key)
		{
			if (key)
				return this.metadata[key];
			else
				return this.metadata;
		};
		this.setMetadata = function(metadataName, value)
		{
			this.metadata[metadataName] = value;
			$(this).trigger("metadata_change", {
				"metadataName" : metadataName,
				"value" : value
			});
		}
	}

	function metadata_viewtable(control)
	{
		this.control = control;
		this.settingPanel = $("#form-control-setting");
		this.linkageMetadata = function(metadataName, value)
		{
			this.control.setMetadata(metadataName, value);
		}
		this.SIZE = function()
		{
			var metadataName = "SIZE";
			var view = $($("#" + metadataName).html());
			var metadata = this.control.getMetadata();
			var _this = this;
			var mValue = metadata[metadataName];
			$(view).find("input[name=width]").val(mValue.WIDTH);
			$(view).find("input[name=height]").val(mValue.HEIGHT);
			$(view).find("input").keyup(function()
			{
				_this.linkageMetadata(metadataName, {
					WIDTH : $("input[name=width]").val(),
					HEIGHT : $("input[name=height]").val()
				});
			});
			$(this.settingPanel).append(view);
		}
		this.TITLE = function()
		{
			var metadataName = "TITLE";
			var view = $($("#" + metadataName).html());
			var metadata = this.control.getMetadata();
			var _this = this;
			var mValue = metadata[metadataName];
			/** 赋值 */
			if (mValue)
			{
				var HIDE = mValue["HIDE"];
				$(view).find("input:checkbox[name='SHOW']").prop("checked", HIDE);
				var TEXT = mValue["TEXT"];
				$(view).find("input:text").val(TEXT);
			}

			$(view).find("input:checkbox[name='SHOW']").on("change", function()
			{
				var value = $(this).prop("checked");
				mValue["HIDE"] = value;
				_this.linkageMetadata(metadataName, mValue);
			});
			$(view).find("input:text").on("keyup", function()
			{
				var value = $(this).val();
				mValue["TEXT"] = value;
				_this.linkageMetadata(metadataName, mValue);
			});
			$(this.settingPanel).append(view);
		};
	}

	function metadata_form_viewtable(control)
	{
		this.control = control;
		this.TITLE = function(value)
		{
			var label = $(this.control).find("em");
			var TEXT = value["TEXT"];
			$(label).html(TEXT);
			var HIDE = value["HIDE"];
			if (HIDE)
			{
				$(this.control).find("h4").hide();
			} else
			{
				$(this.control).find("h4").show();
			}
		}
		this.SIZE = function(value)
		{
			$(control).find(".table-div").height(value.HEIGHT);
			$(control).find(".table-div").width(value.WIDTH + "%");
		}
	}
</script>
</div>
